// PlugInInstallDialog.cpp : implementation file
//

#include "stdafx.h"
#include "PlugInInstallDialog.h"
#include "shlobj.h"

// CPlugInInstallDialog dialog

IMPLEMENT_DYNAMIC(CPlugInInstallDialog, CDialog)

CPlugInInstallDialog::CPlugInInstallDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CPlugInInstallDialog::IDD, pParent)
	, m_strPlguInName(_T(""))
	, m_strInstallDir(_T(""))
	, m_bCreateInstallDirectory(TRUE)
	, m_bShowPluginHelp(TRUE)
	, m_bLaunchVS(TRUE)
	, m_iLanguage(0)
	, m_strPlugInDescription(_T(""))
{

}

CPlugInInstallDialog::~CPlugInInstallDialog()
{
}

void CPlugInInstallDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT_PLUGIN_NAME, m_strPlguInName);
	DDX_Text(pDX, IDC_EDIT_INSTALL_DIR, m_strInstallDir);
	DDX_Check(pDX, IDC_CHECK_CREATE_NEW_DIRECTORY, m_bCreateInstallDirectory);
	DDX_Check(pDX, IDC_CHECK_LAUNCH_HELP, m_bShowPluginHelp);
	DDX_Check(pDX, IDC_CHECK_LAUNCH_VS, m_bLaunchVS);
	DDX_Check(pDX, IDC_CHECK_LAUNCH_FOLDER, m_bLaunchFolder);
	DDX_Text(pDX, IDC_EDIT_PLUGIN_DESCRIPTION, m_strPlugInDescription);
}


BEGIN_MESSAGE_MAP(CPlugInInstallDialog, CDialog)

	ON_BN_CLICKED(IDC_BUTTON_DIR_BROWSE, &CPlugInInstallDialog::OnBnClickedButtonDirBrowse)
	ON_BN_CLICKED(IDOK, &CPlugInInstallDialog::OnBnClickedOk)
END_MESSAGE_MAP()


// CPlugInInstallDialog message handlers

void CPlugInInstallDialog::OnBnClickedOk()
{
	// 
	UpdateData(TRUE);
	if ( m_strPlguInName.IsEmpty() == TRUE )
	{
		AfxMessageBox(_T("Plugin Name field is empty"));
		return;
	}

	if ( m_strPlugInDescription.IsEmpty() == TRUE )
	{
		AfxMessageBox(_T("Plugin Description field is empty"));
		return;
	}

	if ( m_strInstallDir.IsEmpty() == TRUE )
	{
		AfxMessageBox(_T("Plugin Install Directory field is empty"));
		return;
	}

	INT32 checkedID = GetCheckedRadioButton(IDC_RADIO_CS, IDC_RADIO_VB);
	m_iLanguage = checkedID-IDC_RADIO_CS;

	OnOK();
}

void CPlugInInstallDialog::OnBnClickedButtonDirBrowse()
{
	// 
	UpdateData(TRUE);

	BROWSEINFO bi = { 0 };
	TCHAR path[MAX_PATH];
	bi.lpszTitle = _T("Pick a Directory");
	bi.ulFlags = BIF_EDITBOX|BIF_USENEWUI;
	LPITEMIDLIST pidl = SHBrowseForFolder ( &bi );
	if ( pidl != 0 )
	{
		// get the name of the folder
		TCHAR path[MAX_PATH];
		if ( SHGetPathFromIDList ( pidl, path ) )
		{
			m_strInstallDir = CString(path);
		}

		// free memory used
		IMalloc * imalloc = 0;
		if ( SUCCEEDED( SHGetMalloc ( &imalloc )) )
		{
			imalloc->Free ( pidl );
			imalloc->Release ( );
		}
	}

	UpdateData(FALSE);
}


BOOL CPlugInInstallDialog::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 
	((CButton*)GetDlgItem(IDC_RADIO_CS))->SetCheck(1);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}
